
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
from . import constants


def check_access_token(token):
    # 创建工具
    serializer = Serializer(settings.SECRET_KEY, expires_in=constants.ACCESS_TOKEN_EXPIRES)
    # 拿到token
    openid = serializer.loads(token)

    return openid

def generate_access_token(openid):
    # 创建工具
    serializer = Serializer(settings.SECRET_KEY, expires_in=constants.ACCESS_TOKEN_EXPIRES)
    # 拿到openid
    data = {'openid': openid}
    # 序列化/签名
    token = serializer.dumps(data)

    return token.decode()

